#ifndef __UTILS_H__
#define __UTILS_H__

/* -- INCLUDES  ------------------------------------------------------------ */
#include <stdio.h>

/* -- DEFINES -------------------------------------------------------------- */
#define DEBUGME

#ifdef DEBUGME
	#define DEBUG(format, ...)	do {										\
									printf(format, __VA_ARGS__);			\
								} while(0)
	#define ERROR(format, ...)	do {										\
									fprintf(stderr, format, __VA_ARGS__);	\
								} while(0)
	#define PERROR(pstr)		do {										\
									perror(pstr);							\
								} while(0)
#else
	#define DEBUG(format, ...)	do {} while(0)
	#define ERROR(format, ...)	do {} while(0)
	#define PERROR(pstr)		do {} while(0)
#endif


#define FFATAL(format, ...)		do {										\
									ERROR(format, __VA_ARGS__);				\
									exit(EXIT_FAILURE);						\
								} while(0)

#define PFATAL(msg)				do {										\
									PERROR(msg);							\
									exit(EXIT_FAILURE);						\
								} while(0)

#define FATAL(msg)				do {										\
									fprintf(stderr, "%s", msg);				\
									exit(EXIT_FAILURE);						\
								} while(0)

#define QUEUE_MSG_SIZE			(sizeof(msg_t) - 1) /* char text[1] */
#define QUEUE_LOG_SIZE			(sizeof(log_t) - sizeof(long int))
#define MAX_MSG_SIZE			( QUEUE_MSG_SIZE + PATH_MAX + 1 )

/* -- TYPES ---------------------------------------------------------------- */
typedef enum { NONE, INFO, IMPORTANT, WARNING, ERROR, SUCCESS } level_t;

typedef enum { MOTHER, LAUNCHER, LOGGER, WATCHER } task_t;

typedef enum { false = 0, true = 1 } bool_t;

typedef struct msg_s {
	long int type;
	char text[1]; /* variable length array */
} msg_t, *msg_p;

typedef struct log_s {
	long int type;
	task_t task;
	level_t level;
	int arg;
} log_t, *log_p;

#endif /* __UTILS_H__ */
